package com.app.zhuozhuo

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_web.*

/**
 *  Create by zhouwd on 2020-01-09
 *  Describe:
 */

/**
 * 跳转到当前页面
 */
private const val EXTRA_URL = "extra_url"

fun WebActivity_instance(context: Context, url: String) {
    Log.i(TAG, "WebActivity_instance ---> url --> $url")
    val intent = Intent()
    intent.setClass(context, WebActivity::class.java)
    intent.putExtra(EXTRA_URL, url)
    context.startActivity(intent)
}

private val TAG = WebActivity::class.java.simpleName

class WebActivity : AppCompatActivity() {

    private val webView = WebViewFactory_get()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_web)

        val url = intent.getStringExtra(EXTRA_URL)
        webView?.clearView()
        webView?.settings?.blockNetworkImage = false
        webView?.loadUrl(url)
        Log.i(TAG, "webView --> ${webView?.url} ---> url --> $url")
        activity_web_container.addView(webView)
    }

    override fun onStop() {
        super.onStop()
        activity_web_container.removeView(webView)
    }
}